home *** CD-ROM | disk | FTP | other *** search
/ A.C.E. 1 / ACE CD 1.iso / files / utils / rexxplus.dms / in.adf / clizap.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1992-06-23  |  8.1 KB  |  248 lines

  1. /*************************************************************************/
  2. /*                                     */
  3. /* CliZap.rexx:    Copyright © 1991-92, Dineen Edwards Group, Inc.      */
  4. /*        All rights reserved.                     */
  5. /*                                     */
  6. /*    program to enter relative offsets, verify data, and replacement  */
  7. /*    data, for the purpose of zapping an object file to fix bugs. The */
  8. /*    data can be entered as a file or from the cli.             */
  9. /*                                     */
  10. /*    When a list of blank delimited file names are specified, the      */
  11. /*     files are used as input for the zap application. When no     */
  12. /*    parameters are specified, the data is to be entered from the CLI.*/
  13. /*    The data from the CLI or from the file is in the following     */
  14. /*    format:                                 */
  15. /*                                     */
  16. /*        File Name:   -    name of file to zap.             */
  17. /*                                     */
  18. /*        Offset:         -    offset from start of file for zap.     */
  19. /*                specified as newzap decimal sector and      */
  20. /*                and hexidecimal cursor, or as decimal     */
  21. /*                relative offset.             */
  22. /*        Verify Data: -    Hexidecimal data at the location to be      */
  23. /*                zapped.                     */
  24. /*        Replace Data: -    Hexidecimal data to be placed at location*/
  25. /*                offset.                     */
  26. /*                    *    the Offset, Verify, and Replace data      */
  27. /*                prompts are read until a null line is     */
  28. /*                read. Once read, the next two prompts     */
  29. /*                are given.                 */
  30. /*                                     */
  31. /*        Check Sum:    - Hexidecimal check sum used to verify      */
  32. /*                accuracy of data entered.         */
  33. /*        Apply Zap:    - Yes to apply zap. No to skip application.*/
  34. /*                                     */
  35. /*************************************************************************/
  36.  
  37. /*************************************************************************/
  38. /*************************************************************************/
  39. /**                                    **/
  40. /**              * * *    Warning * * *                **/
  41. /**                                    **/
  42. /**    This program was written to modify object libraries. Modifying  **/
  43. /**    modifying object libraries can have catastrophic results.    **/
  44. /**                                    **/
  45. /**            * * * USE AT YOUR OWN RISK * * *            **/
  46. /**                                    **/
  47. /**                                    **/
  48. /*************************************************************************/
  49. /*************************************************************************/
  50.  
  51. numeric digits 14
  52. say "CliZap.rexx:    Copyright © 1991-92, Dineen Edwards Group, Inc.,"
  53. say "        All rights reserved." 'a'x
  54.  
  55. parse arg files        /* get the list of zap files */
  56. min = 18        /* set minimum prompt length */
  57.  
  58. if files = '' then files = '*'    /* if no file list, set file to CLI */
  59. error2 = 0            /* set error level */
  60.  
  61. do while files ~= ''            /* loop through list of files */
  62.     parse var files inpt files    /* find first file and leave rest */
  63.     call close(STDIN)        /* close STDIN file handle */
  64.     if ~open(STDIN,inpt,'r')    /* reopen STDIN for first file */
  65.     then do                /* on error, give error and exit */
  66.         say "Input file '"inpt"' not found."
  67.         exit 20
  68.         end
  69.  
  70.     file = GetLine('Enter file name:')    /* get the file name */
  71.     
  72.     /* display status of zap */
  73.     say
  74.     say "Processing zaps from '"inpt"'"
  75.     say "Zapping file '"file"'"
  76.  
  77.     chksum = 0            /* set default check sum to zero */
  78.     error = 0            /* set errors off */
  79.     applied = 0            /* set applied off */
  80.     zap = 0                /* set zap count for array to zero */
  81.     off. = ""            /* set compounds to null */
  82.     data. = ""            /* set compounds to null */
  83.  
  84.     if ~open('f',file,'A')        /* open file to be zapped */
  85.     then do
  86.         say "Can't open '"file"'."    /* on error, say it */
  87.         exit 10                /* exit on error */
  88.         end
  89.  
  90.     do forever                /* loop until null response */
  91.         ioerr = 0            /* set i/o error flag off */
  92.         a = GetLine('Offset:')        /* get verify data */
  93.         parse var a o p .        /* get the offset */
  94.         o = translate(o,' ',',')    /* make commas, spaces */
  95.         if o = '' then leave        /* null leave forever loop */
  96.         if ~datatype(o,'n')
  97.         then do
  98.             say 'Offset' d 'not specified as a decimal'
  99.             error = 1
  100.             end
  101.  
  102.  
  103.         if p~=''                /* newzap format? */
  104.         then do
  105.             if ~datatype(p,'x')        /* check validity of position */
  106.             then do
  107.                 say 'Cursor position' p 'not specified in hexadecimal'
  108.                 error = 1
  109.                 end
  110.             else o = (o-1)*512+x2d(p)    /* calculate decimal offset */
  111.             end
  112.  
  113.         if inpt ~= '*' | ~error            /* only if not error */
  114.         then do
  115.             a = GetLine('Verify Data:')    /* get verify data */
  116.             parse var a v comm        /* separate it */
  117.             v = translate(v,' ',',')    /* make commas, spaces */
  118.             if v = '' then leave        /* null leave forever loop */
  119.             if datatype(v,'x')
  120.             then v = x2c(v)            /* make character string */
  121.             else do
  122.                 say 'Verify Data is not valid hexadecimal'
  123.                 error = 1
  124.                 end
  125.             end
  126.  
  127.         if inpt ~= '*' | ~error                /* only if not error */
  128.         then do
  129.             a = GetLine('Replace Data:')    /* get replacement data */
  130.             parse var a r comm        /* separate it */
  131.             r = translate(r,' ',',')    /* make commas, spaces */
  132.             if r = '' then leave        /* null leave forever loop */
  133.             if datatype(r,'x')
  134.             then r = x2c(r)            /* make character string */
  135.             else do
  136.                 say 'Replace Data is not valid hexadecimal'
  137.                 error = 1
  138.                 end
  139.             end
  140.     
  141.         if seek('f',o,'B') = -1            /* seek to the offset */
  142.         then do
  143.             error = 1
  144.             say 'Offset' o 'outside of file being zapped'
  145.             end
  146.         else if inpt ~= '*' | ~error 
  147.              then do
  148.             old = readch('f',length(r))        /* find old data */
  149.  
  150.             if left(old,length(v)) ~== v        /* varify and old data the same? */
  151.             then if (left(old,length(r))) ~== r    /* replacement data same? */
  152.                  then do
  153.                 error = 1            /* no, set error flag */
  154.                 say "Old data '"c2x(old)"' not equal Verify data '"c2x(v)"' at offset" o'.'
  155.                 end
  156.                  else applied = 1            /* set applied flag */
  157.             end
  158.  
  159.         if inpt = '*' & error        /* if from console, and error */
  160.         then do
  161.             error = 0        /* allow continuation after error */
  162.             say '0a'x "Re-enter zap data"    /* tell user what is happening */
  163.             end
  164.         else do
  165.             /* save data and calculate check sum */
  166.             off.zap  = o            /* save the offset in array */
  167.             data.zap = r            /* save replace data in array */    
  168.             ver.zap = v            /* save the verify */
  169.             old.zap = old            /* save old data in array */
  170.  
  171.             /* loop through replacement data for check sum */
  172.             do i = 1 to length(r)
  173.                 chksum = chksum + c2d(substr(r,i,1))
  174.                 end
  175.             chksum = chksum + o        /* add offset for check sum */
  176.             zap = zap + 1            /* increment zap array pointer */
  177.             end
  178.         end
  179.  
  180.     if zap = 0                    /* any, zap data? */
  181.     then do
  182.         say 'No valid zap data entered'        /* tell user what happened */
  183.         exit 5                    /* set the return code */
  184.         end
  185.  
  186.     /* ask for check sum data */
  187.     a = GetLine("Enter Check Sum:")            /* get check sum */
  188.     parse var a a comm                /* separate the data */
  189.     a = translate(a,' ',',')            /* make commas, spaces */
  190.     a = x2d(a)                    /* make it a decimal value */
  191.     if a ~= chksum                    /* check for equality */
  192.     then do
  193.         /* give error, when not equal */
  194.         say "Calculated check sum '"d2x(chksum)"' not equal '"d2x(a)"'."
  195.         error = 1                /* set error flag */
  196.         end
  197.  
  198.     if error                    /* if error found */
  199.     then say 'Prior error disabled zap'        /* display error */
  200.     else do                        /* otherwise... */
  201.         if zap > 0            /* any zap info entered? */
  202.         then do             /* check cor application */
  203.             /* set apply prompt */
  204.             a = GetLine("Apply the zap?")    /* get answer */
  205.             a = word(a,1)            /* get the first word */
  206.             if abbrev("YES",a,1) ~= 0 || abbrev("APPLY",a,1) ~= 0 /* yes, apply it */
  207.             then do
  208.                 if applied
  209.                 then say 'Zap already applied'
  210.                 else do i = 0 to zap-1
  211.                     call seek('f',off.i,'B')    /* seek to offset */
  212.                     call writech('f',data.i)    /* write the data */
  213.                     /* list the update */
  214.                     say "Offset: "off.i" Old Data: "c2x(old.i)" New Data: "c2x(data.i)
  215.                     end
  216.                 end
  217.             else if abbrev("REMOVE",a,1)
  218.                  then do i = 0 to zap-1
  219.                 call seek('f',off.i,'B')    /* seek to offset */
  220.                 call writech('f',ver.i)    /* write the data */
  221.                 /* list the update */
  222.                 say "Offset: "off.i" Old Data: "c2x(old.i)" New Data: "c2x(ver.i)
  223.                 end
  224.                              else do
  225.                 say '0a'x 'Zap not applied'
  226.                     do i = 0 to zap-1        /* list it */
  227.                     say "Offset: "off.i" Current Data: "c2x(old.i)" Replace Data: "c2x(data.i)
  228.                     end
  229.                 end
  230.             end
  231.         end
  232.     call close('f')            /* close the file */
  233.     error2 = error | error2        /* set second error level */
  234.     end
  235.  
  236. if error2 then exit 10            /* give bad return code */
  237. exit
  238.  
  239. GetLine:
  240.     parse arg a
  241.     options prompt left(a,min)        /* set prompt */
  242.     a = '*'
  243.     do while left(a,1) = '*'
  244.         parse upper pull a        /* get the line */
  245.         a = translate(a,' ','    ')    /* make commas, spaces */
  246.         end
  247.     return a
  248.